package com.example.czxyproduct.biz;

import com.example.czxyproduct.mapper.AdvaMapper;
import com.yc.czxy.bean.Adva;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class AdvaBiz {

    @Resource
    AdvaMapper advaMapper;

    // 秒 分 时 天 月 年 6个  月和星期互斥
    //*/1每分钟执行一次
    @Scheduled(cron = "0 0 0 * * ?")
    public void ScheduleAdva(){
        System.out.println("正在执行定时任务======");
        advaMapper.ScheduleUpdate();
    }

    public Adva click(int id){
        advaMapper.updateNum(id);
        Adva adva = advaMapper.selectById(id);
        if(adva.getClickNum() >= adva.getAllNum()){
            //更改状态
            advaMapper.UpdateById(id);
        }
        return adva;
    }
}
